package references

import (
	"hi-jvm/instructions/base"
	"hi-jvm/rtda"
)

// Get static field from class
type GET_STATIC struct{ base.Index16Instruction }

func (self *GET_STATIC) Execute(frame *rtda.Frame) {
	field, class := readStaticClassInfo(self.Index, frame, true)

	if !class.InitClassIfNotInited(frame) {
		return
	}
	stack := frame.OperandStack
	slots := class.StaticVars
	slotId := field.SlotId


	if field.IsInt32() {
		stack.PushInt(slots.GetInt(slotId))
		return
	}

	if field.IsFloat() {
		stack.PushFloat(slots.GetFloat(slotId))
		return
	}

	if field.IsInt64() {
		stack.PushLong(slots.GetLong(slotId))
		return
	}

	if field.IsDouble() {
		stack.PushDouble(slots.GetDouble(slotId))
		return
	}

	if field.IsRef() {
		stack.PushRef(slots.GetRef(slotId))
		return
	}
}